home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / xpdf / h / gfile < prev    next >
Text File  |  2003-02-21  |  4KB  |  154 lines

  1. //========================================================================
  2. //
  3. // gfile.h
  4. //
  5. // Miscellaneous file and directory name manipulation.
  6. //
  7. // Copyright 1996-2002 Glyph & Cog, LLC
  8. //
  9. //========================================================================
  10.  
  11. //========================================================================
  12. //
  13. // Changes marked:
  14. //
  15. //   //**** Colin Granville ****
  16. // To
  17. //   //**** end Colin Granville ****
  18. //
  19. // made by Colin Granville 2003
  20. //
  21. //========================================================================
  22.  
  23. #ifndef GFILE_H
  24. #define GFILE_H
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <stddef.h>
  29. #if defined(WIN32)
  30. #  include <sys/stat.h>
  31. #  ifdef FPTEX
  32. #    include <win32lib.h>
  33. #  else
  34. #    include <windows.h>
  35. #  endif
  36. #elif defined(ACORN)
  37. //**** Colin Granville ****/
  38. #  include <time.h>
  39. //**** end Colin Granville ****/
  40. #elif defined(MACOS)
  41. #  include <ctime.h>
  42. #else
  43. #  include <unistd.h>
  44. #  include <sys/types.h>
  45. #  ifdef VMS
  46. #    include "vms_dirent.h"
  47. #  elif HAVE_DIRENT_H
  48. #    include <dirent.h>
  49. #    define NAMLEN(d) strlen((d)->d_name)
  50. #  else
  51. #    define dirent direct
  52. #    define NAMLEN(d) (d)->d_namlen
  53. #    if HAVE_SYS_NDIR_H
  54. #      include <sys/ndir.h>
  55. #    endif
  56. #    if HAVE_SYS_DIR_H
  57. #      include <sys/dir.h>
  58. #    endif
  59. #    if HAVE_NDIR_H
  60. #      include <ndir.h>
  61. #    endif
  62. #  endif
  63. #endif
  64. #include "gtypes.h"
  65.  
  66. class GString;
  67.  
  68. //------------------------------------------------------------------------
  69.  
  70. // Get home directory path.
  71. extern GString *getHomeDir();
  72.  
  73. // Get current directory.
  74. extern GString *getCurrentDir();
  75.  
  76. // Append a file name to a path string.  <path> may be an empty
  77. // string, denoting the current directory).  Returns <path>.
  78. extern GString *appendToPath(GString *path, char *fileName);
  79.  
  80. // Grab the path from the front of the file name.  If there is no
  81. // directory component in <fileName>, returns an empty string.
  82. extern GString *grabPath(char *fileName);
  83.  
  84. // Is this an absolute path or file name?
  85. extern GBool isAbsolutePath(char *path);
  86.  
  87. // Make this path absolute by prepending current directory (if path is
  88. // relative) or prepending user's directory (if path starts with '~').
  89. extern GString *makePathAbsolute(GString *path);
  90.  
  91. // Get the modification time for <fileName>.  Returns 0 if there is an
  92. // error.
  93. extern time_t getModTime(char *fileName);
  94.  
  95. // Create a temporary file and open it for writing.  If <ext> is not
  96. // NULL, it will be used as the file name extension.  Returns both the
  97. // name and the file pointer.  For security reasons, all writing
  98. // should be done to the returned file pointer; the file may be
  99. // reopened later for reading, but not for writing.  The <mode> string
  100. // should be "w" or "wb".  Returns true on success.
  101. extern GBool openTempFile(GString **name, FILE **f, char *mode, char *ext);
  102.  
  103. // Execute <command>.  Returns true on success.
  104. extern GBool executeCommand(char *cmd);
  105.  
  106. // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
  107. // conventions.
  108. extern char *getLine(char *buf, int size, FILE *f);
  109.  
  110. //------------------------------------------------------------------------
  111. // GDir and GDirEntry
  112. //------------------------------------------------------------------------
  113.  
  114. class GDirEntry {
  115. public:
  116.  
  117.   GDirEntry(char *dirPath, char *nameA, GBool doStat);
  118.   ~GDirEntry();
  119.   GString *getName() { return name; }
  120.   GBool isDir() { return dir; }
  121.  
  122. private:
  123.  
  124.   GString *name;        // dir/file name
  125.   GBool dir;            // is it a directory?
  126. };
  127.  
  128. class GDir {
  129. public:
  130.  
  131.   GDir(char *name, GBool doStatA = gTrue);
  132.   ~GDir();
  133.   GDirEntry *getNextEntry();
  134.   void rewind();
  135.  
  136. private:
  137.  
  138.   GString *path;        // directory path
  139.   GBool doStat;            // call stat() for each entry?
  140. #if defined(WIN32)
  141.   WIN32_FIND_DATA ffd;
  142.   HANDLE hnd;
  143. #elif defined(ACORN)
  144. #elif defined(MACOS)
  145. #else
  146.   DIR *dir;            // the DIR structure from opendir()
  147. #ifdef VMS
  148.   GBool needParent;        // need to return an entry for [-]
  149. #endif
  150. #endif
  151. };
  152.  
  153. #endif
  154.